package com.logistics.map.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.logistics.map.entity.domain.MapRouteEdges;
import com.logistics.map.entity.model.MapRouteEdgesRow;
import com.logistics.map.entity.model.MapRouteEdgesSave;
import com.logistics.map.mapper.MapRouteEdgesMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MapRouteEdgesService extends ServiceImpl<MapRouteEdgesMapper, MapRouteEdges> {

    /**
     * 保存
     * @param save
     */
    public void save(MapRouteEdgesSave save){
        this.save(MapRouteEdges.build(save));
    }

    /**
     * 删除
     * @param codes
     */
    public void deleteByRouteCode(List<String> codes){
        this.remove(new LambdaQueryWrapper<MapRouteEdges>().in(MapRouteEdges::getRouteCode, codes));
    }

    /**
     * 根据code查找线边
     * @param codes
     * @return
     */
    public List<MapRouteEdgesRow> listByCode(List<String> codes){
        return this.list(new LambdaQueryWrapper<MapRouteEdges>().
                in(MapRouteEdges::getRouteCode, codes)).stream().
                map(e -> MapRouteEdgesRow.build(e)).collect(Collectors.toList());
    }
}
